package studychinese.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hschinese.pronunciation.R;
import com.hschinese.pronunciation.bean.TestChinesePraciticeBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by lenovo on 2017/4/9.
 */
public class GvResultchinaAdapter extends AppAdapter {
    private int mPosstion = -1;
   private List<TestChinesePraciticeBean.DataBean> data;
    public GvResultchinaAdapter(List list, Context context) {
        super(list, context);
     this.data=list;
    }
  /*  */


    @Override
    public View createView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_gv_result_china, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if(data.get(position).isRight()){

            viewHolder.itemGvResultPinyinRight.setVisibility(View.VISIBLE);
            if(data.get(position).getRightHanzi()!=null){
                viewHolder.itemGvResultPinyinRight.setText(data.get(position).getRightHanzi());
            }

            viewHolder.itemGvResultPinyinWrong.setVisibility(View.INVISIBLE);
        }else {
            viewHolder.itemGvResultPinyinRight.setVisibility(View.VISIBLE);
            viewHolder.itemGvResultPinyinWrong.setVisibility(View.VISIBLE);
            viewHolder.itemGvResultPinyinRight.setText(data.get(position).getRightHanzi());
            if(data.get(position).getSeleteHanzi()!=null){

                if(data.get(position).getSeleteHanzi().equals("")){
                    viewHolder.itemGvResultPinyinWrong.setText("("+"空"+")");
                }else {
                    if(data.get(position).getSeleteHanzi()!=null){
                        viewHolder.itemGvResultPinyinWrong.setText("("+data.get(position).getSeleteHanzi()+")");
                    }

                }
            }


        }

        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.item_gv_result_pinyin_wrong)
        TextView itemGvResultPinyinWrong;
        @Bind(R.id.item_gv_result_pinyin_right)
        TextView itemGvResultPinyinRight;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
